<?php
class Http extends Snoopy{

	var $charset = '';
	var $results = '';
	
	function fetch($URI)
	{
		parent::fetch($URI);
		$this->getCharset();
		$this->codeResult();
	}
	
	protected function getCharset()
	{
		if(is_array($this->headers)){
			foreach($this->headers as $header){
				if(stristr($header, "Content-Type")){
					$split = explode(';', $header);
					$split = explode('=', $split[1]);
					$charset = trim($split[1]); break;
				}
			}
		}
		if(empty($charset)){
			$charset = "gbk";
		}
		$this->charset = strtolower($charset);
	}
	
	protected function codeResult()
	{
		if($this->charset == 'utf-8')
			$this->results = parent::$this->results;
		else
			$this->results = iconv($this->charset, 'utf-8//IGNORE', parent::$this->results);
	}
}
?>